

merit <- lm(pub_official_indicator ~ factor(player.gender == 1) + factor(player.education == 4) + factor(player.ethnicity == 1) + factor(player.religion == 1) + factor(player.age > 33), data = main_df %>% filter(group.treatment == "merit"))
random <- lm(pub_official_indicator ~ factor(player.gender == 1) + factor(player.education == 4) + factor(player.ethnicity == 1) + factor(player.religion == 1) + factor(player.age > 33), data = main_df %>% filter(group.treatment == "random") )
patronage <- lm(pub_official_indicator ~ factor(player.gender == 1) + factor(player.education == 4) + factor(player.ethnicity == 1) + factor(player.religion == 1) + factor(player.age > 33), data = main_df %>% filter(group.treatment == "patronage"))

observations <- c(nobs(merit),nobs(random),nobs(patronage))

merit <- coeftest(merit, vcov=vcovHC(merit,type="HC0"))
random <- coeftest(random, vcov=vcovHC(random,type="HC0"))
patronage <- coeftest(patronage, vcov=vcovHC(patronage,type="HC0"))

table <- list(merit, random, patronage)

note_text <- paste("Beta coefficients from OLS regression. Standard errors were calculated using the Huber-White (HC0) correction. 
                   The outcomes measure is whether a player was chosen as the public official, where each column represents one of the different treatment conditions.")

table = stargazer(table, type = 'latex', 
                  title = "The Effect of Selection Mode on Characteristics of Public Official",
                  label = 'tab:first_stage',
                  model.names = F,
                  model.numbers = T,
                  digits = 3,
                  #column.separate = c(1),
                  #column.labels = c("Selection: Merit", "Selection: Random", "Selection: Patronage"),
                  dep.var.labels = "Dependent Variable = Selected", 
                  add.lines = list(c("Observations", observations),
                                   c("Selection:", "Merit", "Sortition", "Patronage")),
                  covariate.labels = c("Gender: Man", "Education: College", "Ethnicity: Javanese", "Religion: Muslim", "Age"),
                  
                  keep.stat = c("n"),
                  notes = NULL,
                  notes.align = 'l')

write_latex(table[-c(10, 11, 17, 20, 23, 26, 29, 32, 38)], note_text, './outputs/tables/table_2.tex', .8)
